package com.example.downloader;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.Toast;

import com.example.downloader.utils.ActivityContext;
import com.example.downloader.utils.PermissionsCheckUtils;

import static com.example.downloader.utils.PermissionsCheckUtils.REQUEST_DODNLOAD;

/**
 * Created by Administrator on 2017/9/22 0022.
 */

public class BaseActivity extends Activity implements ActivityContext {
    private Toast mToast;

    void showToast(String val) {
        if (mToast != null) {
            mToast.cancel();
        }
        mToast = Toast.makeText(this, val, Toast.LENGTH_SHORT);
        mToast.show();
    }

    void showDialog(String val, final DialogInterface.OnClickListener listener) {
        new AlertDialog.Builder(this).setTitle("提示").setMessage(val).setPositiveButton("重新下载", listener).show();
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PermissionsCheckUtils.lackAndRequestPermissions(this, REQUEST_DODNLOAD, PermissionsCheckUtils.STORAGE_PERMISSIONS);
    }

    @Override
    public Activity getActivity() {
        return this;
    }


}
